package io.adrainty.bolee.framework.web.configuration;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.adrainty.bolee.framework.commons.utils.JsonUtil;
import io.adrainty.bolee.framework.web.converter.EnumConverterFactory;
import jakarta.annotation.Nonnull;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <p>FrameworkMvcConfig</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description FrameworkMvcConfig
 * @since 2025/8/1 11:16:59
 */

@Configuration
public class FrameworkWebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addFormatters(@Nonnull FormatterRegistry registry) {
        registry.addConverterFactory(new EnumConverterFactory());
    }

    @Bean
    @ConditionalOnMissingBean
    public ObjectMapper objectMapper() {
        return JsonUtil.getMapper();
    }

    @Bean
    public MultipartResolver multipartResolver() {
        return new StandardServletMultipartResolver();
    }

}
